/**
 * 初始化
 */
$(function () {
    init();
});

/**
 * 加载layui样式
 */
function init() {
    layui.use(['form', 'laydate', 'dtree'], function () {

        var form = layui.form
            , dtree = layui.dtree;

        form.on('radio(menuType)',function (data) {
            switch (data.value) {
                case 'M' :
                    $(".icon").css("display","block");
                    $("#icon").attr("validate","required");
                    $(".url,.perms").css("display","none");
                    $("#url,#perms").removeAttr("validate");
                    $("#url").val("#");
                    $("#perms").val("");
                    break;
                case 'C' :
                    $("#url").val("");
                    $(".url,.perms,.icon").css("display","block");
                    $("#url,#perms,#icon").attr("validate","required");
                    break;
                case 'F' :
                    $(".perms").css("display","block");
                    $("#perms").attr("validate","required");
                    $(".url,.icon").css("display","none");
                    $("#url,#icon").removeAttr("validate");
                    $("#url").val("#");
                    $("#icon").val("");
                    break;
            }
        })
    });
}

/**
 * 设置父级菜单
 */
function setParentId() {
    var parentId = $("#parentId").val();
    var parentName = $("#parentName").val();
    var title = "选择父级菜单信息",
        url = prefixOpen + "/web!system!menu!menuTree!menuTree@parentId=" + parentId + "&parentName=" + parentName,
        width = "20%",
        height = "55%";
    //  打开新窗口
    layTool.openDialog(title, url, width, height, getParentDate);
}
/**
* @Description: 获取父级菜单id和名称
* @Param:
* @return:
* @Author: Mr.Yan
* @Date: 2018/12/20
*/
function getParentDate(index, layero){
    var body = layTool.getChildFrame("body", index);
    $("#parentId").val(body.find('#parentId').val());
    $("#parentName").val(body.find('#parentName').val());
    layTool.closeLayer(index);
}
/**
 * 设置图标按钮
 */
function setIcon() {
    var icon = $("#icon").val();
    var title = "选择图标信息",
        url = prefixOpen + "/web!system!menu!icon!icon@icon=" + icon,
        width = "20%",
        height = "40%";
    //  打开新窗口
    layTool.openDialog(title, url, width, height, getIcon);
}
/**
 * @Description: 获取图标的名字
 * @Param:
 * @return:
 * @Author: Mr.Yan
 * @Date: 2018/12/20
 */
function getIcon(index, layero){
    var body = layTool.getChildFrame("body", index);
    $("#icon").val(body.find('#icon').val());
    layTool.closeLayer(index);
}


